home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / rcs4 / source / rcsfcmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-08  |  7.5 KB  |  235 lines

  1. /*
  2.  *                     RCS file comparison
  3.  */
  4. #ifndef lint
  5. static char rcsid[]= "$Id: rcsfcmp.c 5.2 90/07/15 11:33:36 ROOT_DOS Release $ Purdue CS";
  6. #endif
  7. /*****************************************************************************
  8.  *                       rcsfcmp()
  9.  *                       Testprogram: define FCMPTEST
  10.  *****************************************************************************
  11.  */
  12.  
  13. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  14.    Distributed under license by the Free Software Foundation, Inc.
  15.  
  16. This file is part of RCS.
  17.  
  18. RCS is free software; you can redistribute it and/or modify
  19. it under the terms of the GNU General Public License as published by
  20. the Free Software Foundation; either version 1, or (at your option)
  21. any later version.
  22.  
  23. RCS is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. GNU General Public License for more details.
  27.  
  28. You should have received a copy of the GNU General Public License
  29. along with RCS; see the file COPYING.  If not, write to
  30. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  
  32. Report problems and direct all questions to:
  33.  
  34.     rcs-bugs@cs.purdue.edu
  35.  
  36. */
  37.  
  38.  
  39.  
  40.  
  41.  
  42. /* $Log:    rcsfcmp.c $
  43.  * Revision 5.2  90/07/15  11:33:36  ROOT_DOS
  44.  * checked in with -k by ROOT_DOS at 91.02.07.11.45.22.
  45.  * 
  46.  * Revision 5.2  90/07/15  11:33:36  ROOT_DOS
  47.  * DOS version of RCS 4.0 checked in for MODS
  48.  * by lfk@athena.mit.edu
  49.  * Also update to MSC 6.0
  50.  * 
  51.  * Revision 4.5  89/05/01  15:12:42  narten
  52.  * changed copyright header to reflect current distribution rules
  53.  * 
  54.  * Revision 4.4  88/11/08  12:01:33  narten
  55.  * changes from  eggert@sm.unisys.com (Paul Eggert)
  56.  * 
  57.  * Revision 4.4  88/08/09  19:12:50  eggert
  58.  * Shrink stdio code size.
  59.  * 
  60.  * Revision 4.3  87/12/18  11:40:02  narten
  61.  * lint cleanups (Guy Harris)
  62.  * 
  63.  * Revision 4.2  87/10/18  10:33:06  narten
  64.  * updting version number. Changes relative to 1.1 actually relative to 
  65.  * 4.1
  66.  * 
  67.  * Revision 1.2  87/03/27  14:22:19  jenkins
  68.  * Port to suns
  69.  * 
  70.  * Revision 1.1  84/01/23  14:50:23  kcs
  71.  * Initial revision
  72.  * 
  73.  * Revision 4.1  83/05/10  16:24:04  wft
  74.  * Marker matching now uses trymatch(). Marker pattern is now
  75.  * checked precisely.
  76.  * 
  77.  * Revision 3.1  82/12/04  13:21:40  wft
  78.  * Initial revision.
  79.  *
  80.  */
  81.  
  82. /*
  83. #define FCMPTEST
  84. /* Testprogram; prints out whether two files are identical,
  85.  * except for keywords
  86.  */
  87.  
  88. #include  "rcsbase.h"
  89. extern FILE * fopen();
  90. extern enum markers trymatch(); /* check for keywords */
  91.  
  92.  
  93. rcsfcmp(xfname,uxfname,delta)
  94. char * xfname, *uxfname; struct hshentry *delta;
  95. /* Function: compares the files xfname and uxfname. Returns true
  96.  * if xfname has the same contents as uxfname, while disregarding
  97.  * keyword values. For the LOG-keyword, rcsfcmp skips the log message
  98.  * given by the parameter delta in xfname. Thus, rcsfcmp returns true
  99.  * if xfname contains the same as uxfname, with the keywords expanded.
  100.  * Implementation: character-by-character comparison until $ is found.
  101.  * If a $ is found, read in the marker keywords; if they are real keywords
  102.  * and identical, read in keyword value. If value is terminated properly,
  103.  * disregard it and optionally skip log message; otherwise, compare value.
  104.  */
  105. {
  106.     register int xc,uxc;
  107.     char xkeyword[keylength+2],   uxkeyword[keylength+2];
  108.     char xkeyval[keyvallength+1], uxkeyval[keyvallength+1];
  109.     register FILE * xfp, * uxfp;
  110.     register char * tp;
  111.     int result;
  112.     enum markers match1,match2;
  113.  
  114.     if ((xfp=fopen(tp=xfname,"r"))==NULL || (uxfp=fopen(tp=uxfname,"r"))==NULL) {
  115.        faterror("Can't open %s\n", tp);
  116.        return false;
  117.     }
  118.     result=false;
  119.     xc=getc(xfp); uxc=getc(uxfp);
  120.     while( xc == uxc) { /* comparison loop */
  121.         if (xc==EOF) { /* finished; everything is the same*/
  122.             result=true;
  123.             break;
  124.         }
  125.         if ( xc!=KDELIM) {
  126.             /* get the next characters */
  127.             xc=getc(xfp); uxc=getc(uxfp);
  128.         } else {
  129.             /* try to get both keywords */
  130.             tp = xkeyword;
  131.             while( (xc=getc(xfp))!=EOF && (tp< xkeyword+keylength) && (xc!='\n')
  132.                    && (xc!=KDELIM) && (xc!=VDELIM))
  133.                 *tp++ = xc;
  134.         *tp++ = xc;  /* add closing K/VDELIM */
  135.             *tp='\0';
  136.             tp = uxkeyword;
  137.             while( (uxc=getc(uxfp))!=EOF && (tp< uxkeyword+keylength) && (uxc!='\n')
  138.                    && (uxc!=KDELIM) && (uxc!=VDELIM))
  139.                 *tp++ = uxc;
  140.         *tp++ = xc;  /* add closing K/VDELIM */
  141.             *tp='\0';
  142.             /* now we have 2 keywords, or something thal looks like it.*/
  143.         match1=trymatch(xkeyword,false);
  144.         match2=trymatch(uxkeyword,false);
  145.         if (match1 != match2) break; /* not identical */
  146. #ifdef FCMPTEST
  147.         VOID printf("found potential keywords %s and %s\n",xkeyword,uxkeyword);
  148. #endif
  149.  
  150.         if (match1 == Nomatch) {
  151.         /* not a keyword pattern, but could still be identical */
  152.         if (strcmp(xkeyword,uxkeyword)==0)
  153.              continue;
  154.         else break;
  155.         }
  156. #ifdef FCMPTEST
  157.         VOID printf("found common keyword %s\n",xkeyword);
  158. #endif
  159.         tp=xkeyval;
  160.         if (xc==VDELIM) {/* get value */
  161.         while (((xc=getc(xfp))!=KDELIM) && (xc!='\n') && (xc!=EOF) &&
  162.             (tp<xkeyval+keyvallength))
  163.             *tp++ = xc;
  164.         }
  165.         *tp = '\0';   /*xkeyval now filled with value; possibly empty*/
  166.         tp=uxkeyval;
  167.         if (uxc==VDELIM) {/* get value */
  168.         while (((uxc=getc(uxfp))!=KDELIM) && (uxc!='\n') && (uxc!=EOF) &&
  169.             (tp<uxkeyval+keyvallength))
  170.             *tp++ = uxc;
  171.         }
  172.         *tp = '\0';   /*uxkeyval now filled with value; possibly empty*/
  173.         if (xc!=uxc) break; /* not the same */
  174.         if (xc==KDELIM) {
  175.         xc=getc(xfp); uxc=getc(uxfp); /* skip closing KDELIM */
  176.         /* if the keyword is LOG, also skip the log message in xfp*/
  177.         if (match1==Log) {
  178.             /* first, compute the number of line feeds in log msg */
  179.             int lncnt, ccnt;
  180.             lncnt=2; tp=delta->log;
  181.             while(*tp) if(*tp++=='\n') lncnt++;
  182.             while(xc!=EOF) {
  183.             if (xc=='\n')
  184.                 if(--lncnt==0) break;
  185.             xc=getc(xfp);
  186.             }
  187.             /* skip last comment leader */
  188.             /* Can't just skip another line here, because there may be */
  189.             /* additional characters on the line (after the Log....$)  */
  190.             for (ccnt=strlen(Comment); ccnt>=0; lncnt--) {
  191.             xc=getc(xfp);
  192.             if(xc=='\n') break;
  193.             /* reads to the end of the comment leader or '\n',     */
  194.             /* whatever comes first. This is because some editors  */
  195.             /* strip off trailing blanks from a leader like " * ". */
  196.             }
  197.         }
  198.         } else {
  199.         /* both end in the same character, but not a KDELIM */
  200.         /* must compare string values.*/
  201. #ifdef FCMPTEST
  202.         VOID printf("non-terminated keywords %s, potentially different values\n",xkeyword);
  203. #endif
  204.         if (strcmp(xkeyval,uxkeyval)!=0) break; /*different */
  205.         xc=getc(xfp); uxc=getc(uxfp); /* skip closing char  */
  206.             }
  207.         }
  208.     }
  209.     VOID fclose(xfp); VOID fclose(uxfp);
  210.     return result;
  211. }
  212.  
  213.  
  214.  
  215. #ifdef FCMPTEST
  216. char * RCSfilename, * workfilename;
  217.  
  218. char * Comment;
  219.  
  220. main(argc, argv)
  221. int  argc; char  *argv[];
  222. /* first argument: comment leader; 2nd: log message, 3rd: expanded file,
  223.  * 4th: unexpanded file
  224.  */
  225. {       struct hshentry delta;
  226.  
  227.         cmdid="rcsfcmp";
  228.         Comment=argv[1];
  229.         delta.log=argv[2];
  230.         if (rcsfcmp(argv[3],argv[4],&delta))
  231.                 VOID printf("files are the same\n");
  232.         else    VOID printf("files are different\n");
  233. }
  234. #endif
  235.